<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p>连接状态： <span id="status">未连接</span></p>
    <p>回复消息： <span id="message"></span></p>
    <p><input id="inp"></p>
    <button id="submit">提交</button>

<script>
    let status = document.getElementById("status")
    let message = document.getElementById("message")
    let inp = document.getElementById("inp")
    let submit = document.getElementById("submit")

    let socket = new WebSocket("ws://0.0.0.0:5917/openai/chat")
    socket.addEvenListener("open", (event)=>{
        status.innerText = "已连接"
    })
    socket.addEvenListener("error", (event)=>{
        status.innerText = "已失败"
    })
    socket.addEvenListener("close", (event)=>{
        status.innerText = "已关闭"
    })
    socket.addEvenListener("message", (event)=>{
        message.innerText += event.data
    })

    submit.addEvenListener("click", ()=>{
        socket.send(inp.value)
        message.innerText = ""
    })
</script>
</body>
</html>